package org.vectrics.common.html;

import org.apache.ecs.html.TD;
import org.apache.ecs.html.TR;
import org.apache.ecs.html.Table;
import org.apache.ecs.Element;
import org.apache.log4j.Category;

 
 
public class BorderCell extends Cell {
    private static Category log = Category.getInstance(BorderCell.class);
    private Cell childCell = null;
    
    public BorderCell() {
        
        super();
        log.debug("BorderCell() - constructor called.");

        log.debug("BorderCell() - creating inner table.");

        Table innerTable = new Table();
        innerTable.setCellSpacing(0);
        innerTable.setCellPadding(2);
        innerTable.setWidth("100%");
        innerTable.setHeight("100%");

        super.addElement(innerTable);

        log.debug("BorderCell() - creating inner row.");
        TR row = new TR();
        innerTable.addElement(row);
        
        log.debug("BorderCell() - creating child cell.");
        childCell = new Cell();

        log.debug("BorderCell() - adding child cell to table.");
        row.addElement(childCell);
        childCell.setVAlign("top");
        setClass(null);
    }

    public Element setClass(String className) {
    	if (className == null) {
    		childCell.setBgColor("#ffffff");
			super.setBgColor("#ffffff");
    	}
    	else {
			childCell.setClass(className);
			super.setClass(className);
    	}

        return(this);
    }
    
	public void setDefaultFontClass(String defaultFontClass) {
		super.setDefaultFontClass(defaultFontClass);
		this.childCell.setDefaultFontClass(defaultFontClass);
	}
    
	public TD setBackground(String defaultBgImage) {
		childCell.setBackground(defaultBgImage);
		super.setBackground(defaultBgImage);
		return this;
	}

    public TD setBgColor(String color) {
        childCell.setBgColor(color);
        setClass(null);
        return(this);
    }
    
    public TD addElement(Element theElement) {
        log.debug("addElement() - called.  ");
        childCell.addElement(theElement);
        return(this);
    }
    
    public TD addElement(String theElement) {
        log.debug("addElement() - called.");
        //log.debug("addElement() - called.  inner cell = " +  innerCell.toString());
        childCell.addElement(theElement);
        return(this);
    }
    

}